package com.atguigu.dga.governance.assessor.calc;

import com.atguigu.dga.ds.bean.TDsTaskInstance;
import com.atguigu.dga.ds.service.TDsTaskInstanceService;
import com.atguigu.dga.governance.assessor.Assessor;
import com.atguigu.dga.governance.bean.AssessParam;
import com.atguigu.dga.governance.bean.GovernanceAssessDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Description: 计算中是否有报错指标
 * @Author: lay
 * @Date: 2024/6/30 13:00
 */
@Component("TABLE_TASK_FAIL")
public class TableTaskFailAssessor extends Assessor {
    
    @Autowired
    private TDsTaskInstanceService tDsTaskInstanceService;
    
    @Override
    public void checkProblem(GovernanceAssessDetail governanceAssessDetail, AssessParam assessParam) throws Exception {
        List<TDsTaskInstance> failTDsTaskInstanceList = tDsTaskInstanceService.getFailTDsTaskInstanceList(
                assessParam.getTableMetaInfo().getSchemaName() + "." + assessParam.getTableMetaInfo().getTableName(),
                assessParam.getAssessDate()
        );
        
        if (failTDsTaskInstanceList.size() > 0) {
            governanceAssessDetail.setAssessScore(BigDecimal.ZERO);
            governanceAssessDetail.setAssessProblem("计算中有报错");
        }
    }
}
